<template>
  <div class="container">
    <div class="header-box">
      <h1>康富国际货运代理有限公司</h1>
    </div>
    <div class="tips-box">
      <span>选择您的货是送哪个仓库名，点击进入开单</span>
    </div>
    <div class="warehouse-list">
      <van-cell
        is-link
        v-for="item in companyList"
        :title="item.cname"
        :label="item.address"
        :key="item.id"
        :to="`/create-order?companyId=${item.id}`"
      />
    </div>
    <div class="bottom-box">
      <!--      <div class="query-order-ben" @click="Login">查询订单</div>-->
      <van-row>
        <van-col span="8" class="user-type-item" @click="Login(1)">
          <p>我是客户</p>
          <p>Customer</p>
        </van-col>
        <van-col span="8" class="user-type-item" @click="Login(2)">
          <p>我是仓管</p>
          <p>Managers</p>
        </van-col>
        <van-col span="8" class="user-type-item" @click="Login(3)">
          <p>我是财务</p>
          <p>Finance</p>
        </van-col>
      </van-row>
    </div>
    <van-overlay :show="show" :z-index="999">
      <div class="wrapper">
        <van-loading color="#1989fa" vertical>加载中...</van-loading>
      </div>
    </van-overlay>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { findCompanyList } from "@/api/system";
import { Loading, Overlay } from "vant";

@Component({
  components: {
    Loading,
    Overlay,
  },
})
export default class HomeView extends Vue {
  // 公司列表
  private companyList: any = [];
  // 加载遮罩
  private show = true;

  // 生命钩子
  private async created(): Promise<void> {
    this.companyList = (await findCompanyList()).data;
    this.show = false;
  }

  private Login(type: number): void {
    if (type === 1) {
      if (!localStorage.getItem("customer-token")) {
        this.$router.push("/customer-login");
      } else {
        this.$router.push("/customer-index");
      }
    } else if (type === 2) {
      if (!localStorage.getItem("manager-token")) {
        this.$router.push("/login");
      } else {
        this.$router.push("/manager-index");
      }
    } else {
      if (!localStorage.getItem("manager-token")) {
        this.$router.push("/login");
      } else {
        this.$router.push("/manager-index");
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.container {
  width: 100%;
  height: 100%;

  .header-box {
    width: 100%;
    height: 100px;
    display: flex;
    font-size: 12px;
    align-items: center;
    justify-content: center;
  }

  .tips-box {
    width: 100%;
    height: 30px;
    display: flex;
    align-items: center;
    box-sizing: border-box;
    padding-left: 20px;
  }

  .warehouse-list {
    width: 100%;
    height: calc(100% / 1 - 190px);
    box-sizing: border-box;
    padding: 5px;

    .van-cell {
      padding: 20px 16px;
      font-size: 18px;
      font-weight: 600;
    }

    overflow-y: auto;
  }

  .bottom-box {
    width: 100%;
    height: 60px;
    background: #ffffff;
    //-moz-box-shadow: 0px -2px 5px #d6d6d6;
    //-webkit-box-shadow: 0px -2px 5px #d6d6d6;
    //box-shadow: 0px -2px 5px #d6d6d6;
    position: fixed;
    bottom: 0;
    z-index: 99;

    .user-type-item {
      height: 60px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      border: 1px #dcdcdc solid;
      border-right: 0;
      line-height: 20px;
    }

    .user-type-item:active {
      background-color: rgba(61, 58, 58, 0.1);
    }

    .user-type-item:focus {
      background-color: rgba(255, 255, 255, 0);
    }
  }

  .van-overlay {
    background-color: rgba(0, 0, 0, 0);
  }

  .wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
</style>
